require("../meituConfig.js");
var o = require("tuyoosdk"), i = {
    name: "meituSDKh5",
    SESSION_KEY: "TY_SZ_SESSION_STORAGE",
    ctor: function () {
        console.log("sdk ctor:", this.name), Global.config.CLIENTID = "H5_5.1200_meitu.meitu.0-hall201.meitu.tysc",
            Global.config.intClientId = 23806, Global.config.cloudId = 17, Global.config.packageName = "com.tyscmj.game.meitu";
    },
    login: function () {
        this.init();
    },
    decode: function (e) {
        return console.log("sdk decode data:"), Global.utils.decodeMessageTy(e);
    },
    init: function () {
        var e = this, t = {
            title: "途游四川麻将",
            pic: Global.config.resUrl + "/share/33.jpg?md5=" + cc.sys.now(),
            summary: "我们只差一场牌局的距离，点击就会有故事......"
        }, n = {
            reset_guest: !1,
            debug: Global.config.isDebug,
            baseurl: Global.config.loginUrl,
            bi_base_url: "https://cbi.touch4.me/",
            appId: Global.config.appId,
            gameId: Global.config.GAMEID,
            cloudId: Global.config.cloudId,
            clientId: Global.config.CLIENTID,
            wxAppId: Global.config.wxAppId,
            packageName: Global.config.packageName,
            pay_version: "hall51",
            share: t,
            sandbox: !0
        }, i = o.CheckChannel();
        o.IsNull(i) && (i = "guest"), "meitu.h5" === i ? (n.packageName = Global.config.packageName,
            n.clientId = Global.config.CLIENTID) : "oppo.h5" === i ? (n.packageName = "com.chinesechess.game.nearme.gamecenter",
            n.clientId = "H5_5.01_oppo.oppo.0-hall3.oppo.bs") : "wxapp" === i ? (n.packageName = Global.config.packageName,
            n.clientId = "H5_4.58_weixin.weixin.0-hall201.weixin.sc", n.wxAppId = "wxa9b801abd43333d9") : "ysdk.h5" === i && (n.packageName = "com.tencent.tmgp.chinesechess.game",
            n.clientId = "H5_5.01_ysdk.ysdk.0-hall3.qq.bs"), o.OnInit(i, n, function (t, n, i) {
            0 === t ? (console.log("初始化成功了:" + n), o.Login({}, function (t, n, o) {
                if (console.log("登陆结果:", t, o), console.log(n), 0 === t) {
                    var i = n.logindata;
                    e.setUserInfo(i);
                    var a = i;
                    Global.userProfile.setUserId(a.userId), Global.userProfile.authorCode = a.authorCode;
                    var r, s = {
                        result: a
                    }, l = a.tcpsrv.ip, c = a.tcpsrv.wsport || a.tcpsrv.port;
                    console.log("loginTuyooWithCode success", "ip:" + l + " port:" + c), r = "wss://" + l + ":" + c.toString() + "/",
                        console.log("loginTuyooWithCode success", "webSocketUrl:" + r), Global.config.host = r,
                        Global.notificationCenter.emit(Global.eventName.MSG_LOGIN_SUCCESS, s);
                }
            }, this)) : (console.log("初始化失败了了!"), console.log(i));
        }, this);
    },
    recharge: function (e) {
        console.log("sdk recharge:", e), o.Pay(e, function (t, n, o) {
            if (console.log("支付结果:", t, o), console.log(n), 0 != t || o) Global.utils.showNodeCommon("支付失败 ", 2); else {
                var i = Global.eventName.CMD_COIN_BUY;
                if (e.buyType == Global.config.buyType.buycoin) {
                    var a = e.prodId;
                    Global.msgHandler.requestPaymentInfo(a);
                } else e.buyType == (Global.config.buyType.zhuanyun || Global.config.buyType.revenge) && Global.msgHandler.requestBuyCoin(i, e.roomId, e.tableId, e.buyType);
            }
        }, this);
    },
    setUserInfo: function (e) {
        e && (Global.userProfile.setUserName(e.userName), Global.userProfile.setUserPic(e.purl),
            Global.userProfile.setUserSex(e.snsSex));
    },
    _showLoginFailAlert: function (e, t) {
        if (!Global.UIPopupManager.getPopupCompByUrl("PopupPanel/PopupAlert")) {
            var n = "";
            n = "登陆失败，请重新登陆", n = t = void 0 == t ? n : t;
            var o = Global.spriteAtlas.getOKSpf();
            Global.utils.showReconnectAlert(n, "确定", o, function () {
                console.log("----------重新登陆--------- "), Global.netWork.closeAndReconnect(5);
            });
        }
    },
    requestBILog: function (e, t) {
        var n = e;
        HttpService.postMethodByUrl(n, t, function (e) {
        }.bind(this), function (e) {
            console.log("requestBILog fail, params:" + JSON.stringify(e));
        }.bind(this));
    },
    shareWithConfig: function (e, t, n, o) {
        var i, a = Global.configCdn.getShareConf().keyConfig || {};
        i = "" == e.content ? null : e.content;
        var r, s = "";
        for (var l in a) switch (l) {
            case "@key1@":
                s = Global.tableModel.getCreateTableNo() + "", i = i.replace(l, s);
                break;

            case "@key2@":
                s = Global.utils.getFixString(Global.userProfile.getUserName(), 5), i = i.replace(l, s);
        }
        if (r = "" == e.shareIcon ? null : Global.config.resUrl + "/share/" + e.shareIcon + ".jpg?md5=" + cc.sys.now(),
        n && n(), mtgsdk) {
            var c = {
                title: i,
                pic: r,
                summary: i,
                callback: function (e) {
                    console.log("shareWithConfig result:", e);
                }
            };
            mtgsdk.openShareLayer(c);
        }
    }
};
module.exports = i
